package zookeeper;

import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

public class ZooKeeperUtil implements Watcher {
	
	private static final Log log = LogFactory.getLog(ZooKeeperUtil.class);
	
	private static final String connectString ="192.168.164.132:2181";
	
	private static final int sessionTimeout = 10000;
	
	private static ZooKeeper zk;
	
	  public static ZooKeeper initZooKeeper(){
		  if(zk==null){
			  try {
					return new ZooKeeper(connectString, sessionTimeout, new ZooKeeperUtil());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		  }
		  return zk;
	  }

	@Override
	public void process(WatchedEvent event) {
		
		log.info(event.getType().toString());
	}

}
